﻿using ConfExpert.Forms.Base;

using DevExpress.XtraPrinting;
using DevExpress.XtraPrinting.Preview;
using DevTeam;

using System;
using System.Data;
using System.IO;

namespace ConfExpert.Forms.Rapor.YeniYapi
{
    public partial class OrtakKumasRaporlari : XForm
    {
        public OrtakKumasRaporlari()
        {
            InitializeComponent();
        }

        void PrintOrtakKumas(object sender, EventArgs e)
        {
            int DosyaId = gvOrtakKumas.GetRowCellValue(gvOrtakKumas.FocusedRowHandle, "DosyaId").ToInt();
            if (DosyaId > 0)
            {
                DataTable dtFoy = ExecuteDataTable("GetOrtakKumasByCikisEmriId", DosyaId);
                byte[] bytes = (byte[])dtFoy.Rows[0]["BLOB"];
                using (MemoryStream stream1 = new MemoryStream(bytes))
                using (PrintingSystem ps = new PrintingSystem())
                using (PrintPreviewFormEx preview = new PrintPreviewFormEx())
                {
                    ps.LoadDocument(stream1);
                    preview.PrintingSystem = ps;
                    preview.ShowDialog();
                }
            }
        }

        private void OrtakKumasRaporlari_Load_1(object sender, EventArgs e)
        {
            this.Text = "Ortak Kumaş Tablosu";
            gvOrtakKumas.Init("GetOrtakKumaslar", WhoAmI);

            gvOrtakKumas.MakeColumnInvisible("DosyaId");
            gvOrtakKumas.MakeReadOnly();

            gvOrtakKumas.BestFitColumns();
            gvOrtakKumas.Columns["DosyaNo"].Width = 100;

            GridManager gm = GridManager.GetManager(gvOrtakKumas);
            gm.GridMenu.AddMenu("Görüntüle", PrintOrtakKumas);
        }

    }
}